import { Engine, Recorder, RecorderData, StartNode } from './engine/index'
import OpenaiNode from './modules/nodes/llm/OpenaiNode'
export default class Recorder2 extends Recorder {
    constructor(options: any) {
        console.log('constructor dddddd', options)
        super(options)
    }
    async addActionRecord(action: RecorderData) {
        super.addActionRecord(action)
        console.log('addActionRecord', action)
    }

    async getActionRecord(actionId: string): Promise<RecorderData> {
        console.log('getActionRecord', actionId)
        return super.getItem(actionId);
    }
    async getExecutionActions(executionId) {
        console.log('getExecutionActions', executionId)
        return super.getItem(executionId);
    }
}

// console.log(Engine);
export async function test() {
    const engine = new Engine({
        // debug: true
    });
    const flowData = {
        graphData: {
            nodes: [
                {
                    id: 'node1',
                    type: StartNode.nodeTypeName,
                    properties: { sss: "ffff" }
                },
                {
                    id: 'node2',
                    type: OpenaiNode.nodeTypeName,
                    properties: {
                        messages: [
                            ["system", "You are a good ai."],
                            ["user", "{sss}"],
                        ]
                    }
                }
            ],
            edges: [
                {
                    id: 'edge1',
                    sourceNodeId: 'node1',
                    targetNodeId: 'node2',
                }
            ]
        },
        globalData: {
            sss: '1+1=?'
        }

    }
    engine.register({
        type: OpenaiNode.nodeTypeName,
        model: OpenaiNode,
    });
    engine.setCustomRecorder(
        new Recorder2({ instanceId: '1234' })
    );
    engine.load(flowData);
    const result = await engine.execute();
    const executionId = result.executionId;
    const execution = await engine.getExecutionRecord(executionId);
    console.log('execution', execution)
    // expect(execution.length).toBe(2);
    // expect(execution[1]).toHaveProperty('actionId');
    // expect(execution[1]).toHaveProperty('nodeId');
    // expect(execution[1]).toHaveProperty('executionId');
    // expect(execution[1]).toHaveProperty('nodeType');
    // expect(execution[1]).toHaveProperty('timestamp');
    // expect(execution[1]).toHaveProperty('properties');
    // expect(execution[1].nodeId).toBe('node2');
    // expect(execution[1].nodeType).toBe('TaskNode');
    // const executionIds = await engine.getExecutionList();
    // expect(executionIds.length).toBe(1);
}